package com.itheima.dubbo.mysql.impl;


import com.alibaba.dubbo.config.annotation.Service;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.itheima.commons.model.domain.Character;
import com.itheima.dubbo.interfaces.CharacterApi;
import com.itheima.dubbo.mysql.mapper.CharacterMapper;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;


@Service
public class CharacterApiImpl implements CharacterApi {

    @Autowired
    private CharacterMapper characterMapper;

    /**
     * 根据成绩，来得知成绩在其中区间的对象
     * @param score
     * @return
     */
    @Override
    public Character queryByScore(long score) {
        Character character = characterMapper.selectOne(Wrappers
                .lambdaQuery(Character.class)
                .le(Character::getScoreMin, score)
                .gt(Character::getScoreMax, score));
        return character;
    }

    /**
     * 返回所以的类型
     * @return
     */
    @Override
    public List<Character> fandAll() {
        List<Character> characters = characterMapper.selectList(Wrappers.lambdaQuery(Character.class));
        return characters;
    }

    /**
     * 根据id查
     * @param characterId
     * @return
     */
    @Override
    public Character queryById(Long characterId) {
        Character character = characterMapper.selectOne(Wrappers
                .lambdaQuery(Character.class)
                .eq(Character::getId, characterId));
        return character;
    }
}
